home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_3 / psm / source / newscrn.c < prev    next >
C/C++ Source or Header  |  1993-07-28  |  57KB  |  1,674 lines

  1.  
  2. #include "psm.h"
  3.  
  4. /**
  5.  ** Definition of newscrn window
  6.  **/
  7.  
  8. enum {
  9.     
  10.     PUBNAME_ID = 1,
  11.     TITLE_ID,
  12.  
  13.     MODELIST_ID,
  14.     MODEINFO_ID,
  15.  
  16.     STDCLIP_ID,
  17.     MINCLIPX_ID,
  18.     MINCLIPY_ID,
  19.     MAXCLIPX_ID,
  20.     MAXCLIPY_ID,
  21.     WIDTH_ID,
  22.     DEFWIDTH_ID,
  23.     HEIGHT_ID,
  24.     DEFHEIGHT_ID,
  25.     AUTOSCROLL_ID,
  26.     
  27.     SETFONT_ID,
  28.     SETFONTKEY_ID,
  29.     FONTNAME_ID,
  30.     FONTSIZE_ID,
  31.     
  32.     DEPTH_ID,
  33.     SCRNPAL_ID,
  34.     SCRNPALKEY_ID,
  35.     PALRED_ID,
  36.     PALREDKEY_ID,
  37.     PALGREEN_ID,
  38.     PALGREENKEY_ID,
  39.     PALBLUE_ID,
  40.     PALBLUEKEY_ID,
  41.     
  42.     CURPEN_ID,
  43.     PENPAL_ID,
  44.     PENPALKEY_ID,
  45.     
  46.     OPEN_ID,
  47.     MODIFY_ID,
  48.  
  49.     WINTAGS_ID
  50. };
  51.  
  52. #define CUSTCLIP_GID GO_GRPID_A
  53. #define FOLLOWMOUSE_GID GO_GRPID_B
  54. #define SMALLWIN_GID GO_GRPID_C
  55.  
  56. #define TEXT_LEN 124 //MAXPUBSCREENNAME //252
  57. #define FONT_LEN 32
  58. #define DIMEN_LEN 128
  59.  
  60. #define CLIP_STANDARD 0
  61. #define CLIP_MINIMUM 1
  62. #define CLIP_TEXT 2
  63. #define CLIP_VIDEO 3
  64. #define CLIP_MAXIMUM 4
  65. #define CLIP_CUSTOM 5
  66.  
  67. UBYTE *ClipLabels[] = {
  68.     "Standard", "Minimum", "Text", "Video", "Maximum", "Custom", NULL,
  69. };
  70.  
  71. #define SIZE_PEN_ARRAY 9
  72.  
  73. UBYTE *PenLabels[SIZE_PEN_ARRAY+1] = {
  74.     "Detail", "Block", "Text", "Shine", "Shadow", "Fill", "FillText",
  75.     "Backgrnd", "Highlight", NULL
  76. };
  77.  
  78. #define SIZE_DEPTH_ARRAY 8
  79.  
  80. UBYTE *DepthLabels[SIZE_DEPTH_ARRAY+1] = {
  81.     "2 colors", "4 colors", "8 colors", "16 colors", "32 colors",
  82.     "64 colors", "128 colors", "256 colors", NULL
  83. };
  84.  
  85. #define GOUS_VisibleSize (GOCT_User+1)
  86. #define GOUS_MinimumSize (GOCT_User+2)
  87. #define GOUS_MaximumSize (GOCT_User+3)
  88. #define GOUS_MaximumColors (GOCT_User+4)
  89. #define GOUS_ClippingSize (GOCT_User+5)
  90.  
  91. static ULONG __saveds __interrupt
  92. newscrn_handler(struct GadOutline *go, ULONG command, struct GOIMsg *msg);
  93.  
  94. static ULONG ModeInfoDrawing[] = {
  95.  
  96.     GODT_ResetBounds, GO_FRMBOUNDS(1,1,1,1, 5,5,5,5),
  97.     GODT_SetStdFillPat, 1,
  98.     GODT_ChooseBPen, BACKGROUNDPEN,
  99.     GODT_SetRastMode, FLGALL(JAM2),
  100.     GODT_FillRect, GO_SCLPNT(SHADOWPEN,0,16,63,48),
  101.  
  102.     GODT_SetStdFillPat, 0,
  103.     GODT_DrawStrFrame, GO_SCLPNT(SHADOWPEN,0,16,63,48),
  104.     GODT_ResetBounds, GO_BOXBOUNDS(3,3,3,3),
  105.     GODT_SetTextMode, FLGALL(TXTMD_LEFT | TXTMD_ENDRIGHT | TXTMD_RELTOP),
  106.  
  107.     GODT_SetLeftBound, GO_TSIZE(GOM_Add,2,GOT_Pixels),
  108.     GODT_SetTopBound, GO_TSIZE(GOM_Add,2,GOT_Pixels),
  109.     GODT_MoveTo, GO_SCLPNT(0,0,0,0,0),
  110.     GODT_SetRastMode, FLGALL(JAM1),
  111.     GODT_ChooseTextAPen, SHADOWPEN,
  112.     GODT_DrawText, (ULONG)&"Vis Size: ",
  113.     GODT_DrawTextTag, GOUS_VisibleSize,
  114.     GODT_NewLine, 1,
  115.     GODT_DrawText, (ULONG)&"Min Size: ",
  116.     GODT_DrawTextTag, GOUS_MinimumSize,
  117.     GODT_NewLine, 1,
  118.     GODT_DrawText, (ULONG)&"Max Size: ",
  119.     GODT_DrawTextTag, GOUS_MaximumSize,
  120.     GODT_NewLine, 1,
  121.     GODT_DrawText, (ULONG)&"Max Colors: ",
  122.     GODT_DrawTextTag, GOUS_MaximumColors,
  123.     GODT_NewLine, 1,
  124.     GODT_DrawText, (ULONG)&"Clip: ",
  125.     GODT_DrawTextTag, GOUS_ClippingSize,
  126.  
  127.     GODT_SetLeftBound, GO_TSIZE(GOM_Add,-2,GOT_Pixels),
  128.     GODT_SetTopBound, GO_TSIZE(GOM_Add,-2,GOT_Pixels),
  129.     GODT_MoveTo, GO_SCLPNT(0,0,0,0,0),
  130.     GODT_ChooseTextAPen, FILLPEN,
  131.     GODT_DrawHighText, (ULONG)&"Vis Size: ",
  132.     GODT_DrawTextTag, GOUS_VisibleSize,
  133.     GODT_NewLine, 1,
  134.     GODT_DrawHighText, (ULONG)&"Min Size: ",
  135.     GODT_DrawTextTag, GOUS_MinimumSize,
  136.     GODT_NewLine, 1,
  137.     GODT_DrawHighText, (ULONG)&"Max Size: ",
  138.     GODT_DrawTextTag, GOUS_MaximumSize,
  139.     GODT_NewLine, 1,
  140.     GODT_DrawHighText, (ULONG)&"Max Colors: ",
  141.     GODT_DrawTextTag, GOUS_MaximumColors,
  142.     GODT_NewLine, 1,
  143.     GODT_DrawHighText, (ULONG)&"Clip: ",
  144.     GODT_DrawTextTag, GOUS_ClippingSize,
  145.     TAG_END
  146. };
  147.  
  148. #define FL_LEFT 12
  149. #define FL_MIDLEFT 30
  150. #define FL_TOP 12
  151. #define FL_MIDTOP 22
  152. #define FL_BOTTOM 51
  153. #define FL_RIGHT 51
  154. #define FL_BOLDEN 5
  155.  
  156. #define FL_TABLEFT FL_MIDLEFT+5
  157. #define FL_TABRIGHT FL_RIGHT-5
  158. #define FL_TABBOTTOM FL_MIDTOP+FL_BOLDEN+6
  159.  
  160. static ULONG FolderDrawing[] = {
  161.     GODT_FillRect, GO_SCLPNT(BACKGROUNDPEN,0,0,63,63),
  162.     GODT_DrawStdFrame, GO_SCLPNT(SHINEPEN,0,0,63,63),
  163.     GODT_FillRect,
  164.         GO_SCLPNT(TEXTPEN,FL_LEFT,FL_MIDTOP,FL_LEFT+FL_BOLDEN,FL_BOTTOM),
  165.     GODT_FillRect,
  166.         GO_SCLPNT(TEXTPEN,FL_LEFT,FL_MIDTOP,FL_MIDLEFT,FL_MIDTOP+FL_BOLDEN),
  167.     GODT_MoveTo,
  168.         GO_SCLPNT(0,FL_MIDLEFT,FL_MIDTOP,0,0),
  169.     GODT_DrawTo2,
  170.         GO_SCLPNT(TEXTPEN,FL_TABLEFT,FL_TOP,FL_TABRIGHT,FL_TOP),
  171.     GODT_DrawTo2,
  172.         GO_SCLPNT(TEXTPEN,FL_RIGHT,FL_MIDTOP,FL_RIGHT,FL_BOTTOM),
  173.     GODT_DrawTo,
  174.         GO_SCLPNT(TEXTPEN,FL_LEFT,FL_BOTTOM,0,0),
  175.     GODT_MoveTo,
  176.         GO_SCLPNT(0,FL_MIDLEFT,FL_MIDTOP+FL_BOLDEN,0,0),
  177.     GODT_DrawTo2,
  178.         GO_SCLPNT(TEXTPEN,FL_TABLEFT,FL_TABBOTTOM,FL_RIGHT,FL_TABBOTTOM),
  179.     TAG_END,
  180. };
  181.  
  182. #define STD_REPORT_LEVEL \
  183.           (1L<<GOTYPE_FINE)  | (1L<<GOTYPE_FINE2) \
  184.         | (1L<<GOTYPE_NOTE)  | (1L<<GOTYPE_NOTE2) \
  185.         | (1L<<GOTYPE_WARN)  | (1L<<GOTYPE_WARN2) \
  186.         | (1L<<GOTYPE_ALERT) | (1L<<GOTYPE_ALERT2) | (1L<<GOTYPE_ALERT3) \
  187.         | (1L<<GOTYPE_FAIL)  | (1L<<GOTYPE_FAIL2)  | (1L<<GOTYPE_FAIL3)
  188.  
  189. static ULONG newscrn_outline[] = {
  190.  
  191. GO_OUTLINETAGS(0,0),
  192.     TAG_END,
  193.     GOA_BaseName,           (ULONG)&__BaseName[0],
  194.     GOA_SetUserHandler,     (ULONG)&newscrn_handler,
  195.     GOA_SetTransHookData,   NULL,
  196.     GOA_ErrorReportLevel,   STD_REPORT_LEVEL,
  197.     TAG_END,
  198.  
  199. GO_WINDOWTAGS(0,WINTAGS_ID),
  200.     TAG_END,
  201.     WA_Title,           (ULONG)&"Open Screen",
  202.     WA_ScreenTitle,     (ULONG)&__LongTitle[0],
  203.     WA_IDCMP,           IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
  204.     WA_Activate,        TRUE,
  205.     WA_CloseGadget,     TRUE,
  206.     WA_DepthGadget,     TRUE,
  207.     WA_DragBar,         TRUE,
  208.     WA_SizeGadget,      TRUE,
  209.     WA_SizeBBottom,     TRUE,
  210.     WA_SimpleRefresh,   TRUE,
  211.     WA_BackFill,        NULL,
  212.     TAG_END,
  213.  
  214. GO_COMMANDTAGS(0,0),
  215.     TAG_END,
  216.     TAG_END,
  217.  
  218. GO_VERTGRP(0,0,1),
  219. GOCT_SizeSpaceAbove, GO_TSIZE(GOM_PadSet,50,GOT_PercCharH),
  220. GOCT_SizeSpaceBelow, GO_TSIZE(GOM_PadSet,80,GOT_PercCharH),
  221. GOCT_SizeSpaceLeft, GO_TSIZE(GOM_PadSet,80,GOT_PercCharW),
  222. GOCT_SizeSpaceRight, GO_TSIZE(GOM_PadSet,50,GOT_PercCharW),
  223. TAG_END,
  224.  
  225.     GO_HORIZGRP(0,0,1), TAG_END,
  226.     
  227.         GO_VERTGRP(0,0,1), TAG_END,
  228.         
  229.             GO_VDRAWGRP(0,0,0),
  230.             GOCT_SizeSpaceAbove, GO_TSIZE(GOM_StdSet,50,GOT_PercCharH),
  231.             GOCT_SizeSpaceBelow, GO_TSIZE(GOM_StdSet,50,GOT_PercCharH),
  232.             GOCT_SizeSpaceLeft, GO_TSIZE(GOM_StdSet,50,GOT_PercCharW),
  233.             GOCT_SizeSpaceRight, GO_TSIZE(GOM_StdSet,50,GOT_PercCharW),
  234.             TAG_END,
  235.             GODT_DrawStdFrame, GO_SCLPNT(SHINEPEN,0,0,63,63),
  236.             TAG_END,
  237.         
  238.                 GO_GTBOX(STRING_KIND,0,PUBNAME_ID,0,(ULONG)&"Public _Name:",PLACETEXT_LEFT|NG_HIGHLABEL),
  239.                 GOCT_SetHotKey, HOTKEY_LOWONLY | 'n',
  240.                 TAG_END,
  241.                 GTST_MaxChars, TEXT_LEN,
  242.                 GTST_String, (ULONG)&"",
  243.                 GT_Underscore, '_',
  244.                 GA_Disabled, FALSE,
  245.                 TAG_END,
  246.  
  247.                 GO_GTBOX(STRING_KIND,0,TITLE_ID,0,(ULONG)&"_Title:",PLACETEXT_LEFT|NG_HIGHLABEL),
  248.                 GOCT_SetHotKey, HOTKEY_LOWONLY | 't',
  249.                 TAG_END,
  250.                 GTST_MaxChars, TEXT_LEN,
  251.                 GTST_String, (ULONG)&"",
  252.                 GT_Underscore, '_',
  253.                 GA_Disabled, FALSE,
  254.                 TAG_END,
  255.  
  256.             GO_ENDGRP(),
  257.  
  258.             GO_EMPTYBOX(0,0,0), TAG_END,
  259.  
  260.             GO_HORIZGRP(0,0,1), TAG_END,
  261.             
  262.                 GO_GTBOX(LISTVIEW_KIND, 0, MODELIST_ID, 1,
  263.                     (ULONG)&"_Modes", PLACETEXT_ABOVE|NG_HIGHLABEL),
  264.                 GOCT_SizeBodyHeight, GO_TSIZE(GOM_StdMax,500,GOT_PercCharH),
  265.                 GOCT_SizeUser1, GO_TSIZE(GOM_VarSet,200,GOT_PercCharW),
  266.                 GOCT_CopyUser1ToTag, GTLV_ScrollWidth,
  267.                 GOCT_SetHotKey, 'm',
  268.                 TAG_END,
  269.                 GTLV_Labels, NULL,
  270.                 GTLV_Top, 0,
  271.                 GTLV_Selected, ~0,
  272.                 GTLV_ShowSelected, NULL,
  273.                 GTLV_ScrollWidth, 16,
  274.                 GT_Underscore, '_',
  275.                 GA_Disabled, FALSE,
  276.                 TAG_END,
  277.                 
  278.                 GO_EMPTYBOX(0,0,0), TAG_END,
  279.                 
  280.                 GO_DRAWBOX(GOSD_Normal,0,MODEINFO_ID,1),
  281.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_StdSet,2,GOT_Pixels),
  282.                 GOCT_SizeSpaceRight, GO_TSIZE(GOM_StdSet,2,GOT_Pixels),
  283.                 GOCT_SizeSpaceAbove, GO_TSIZE(GOM_StdSet,1,GOT_Pixels),
  284.                 GOCT_SizeSpaceBelow, GO_TSIZE(GOM_StdSet,1,GOT_Pixels),
  285.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_PadSet,50,GOT_PercCharW),
  286.                 GOCT_SizeSpaceRight, GO_TSIZE(GOM_PadSet,50,GOT_PercCharW),
  287.                 GOCT_SizeSpaceAbove, GO_TSIZE(GOM_PadSet,50,GOT_PercCharH),
  288.                 GOCT_SizeSpaceBelow, GO_TSIZE(GOM_PadSet,50,GOT_PercCharH),
  289.                 GOCT_SizeBodyWidth, GO_TSIZE(GOM_PadSet,500,GOT_PercCharW),
  290.                 GOCT_SizeBodyHeight, GO_TSIZE(GOM_StdSet,300,GOT_PercCharH),
  291.                 TAG_END,
  292.                 GOUS_VisibleSize, NULL,
  293.                 GOUS_MinimumSize, NULL,
  294.                 GOUS_MaximumSize, NULL,
  295.                 GOUS_MaximumColors, NULL,
  296.                 GOUS_ClippingSize, NULL,
  297.                 GODT_ExecDrawing, (ULONG)&ModeInfoDrawing[0],
  298.                 TAG_END,
  299.  
  300.             GO_ENDGRP(),
  301.         
  302.         GO_HORIZGRP(0,0,0), TAG_END,
  303.         
  304.             GO_VERTGRP(SMALLWIN_GID,0,0), TAG_END,
  305.             
  306.                 GO_GTBOX(CYCLE_KIND,0,STDCLIP_ID,0,(ULONG)&"O_verscan:",PLACETEXT_LEFT|NG_HIGHLABEL),
  307.                 GOCT_SetHotKey, 'v',
  308.                 TAG_END,
  309.                 GTCY_Labels, (ULONG)&ClipLabels[0],
  310.                 GTCY_Active, 0,
  311.                 GT_Underscore, '_',
  312.                 GA_Disabled, FALSE,
  313.                 TAG_END,
  314.                 
  315.                 GO_HORIZGRP(0,0,0), TAG_END,
  316.                 
  317.                     GO_GTBOX(INTEGER_KIND,CUSTCLIP_GID,MINCLIPX_ID,1,(ULONG)&"M_in:",PLACETEXT_LEFT|NG_HIGHLABEL),
  318.                     GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdAdd,300,GOT_PercChar0),
  319.                     GOCT_SetHotKey, HOTKEY_LOWONLY | 'i',
  320.                     TAG_END,
  321.                     GTIN_Number, 0,
  322.                     GTIN_MaxChars, 5,
  323.                     GT_Underscore, '_',
  324.                     GA_Disabled, FALSE,
  325.                     TAG_END,
  326.                 
  327.                     GO_GTBOX(TEXT_KIND,0,0,0,(ULONG)&"x",PLACETEXT_IN),
  328.                     TAG_END,
  329.                     GT_Underscore, '_',
  330.                     GA_Disabled, FALSE,
  331.                     TAG_END,
  332.                 
  333.                     GO_GTBOX(INTEGER_KIND,CUSTCLIP_GID,MINCLIPY_ID,1,NULL,0),
  334.                     GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdAdd,300,GOT_PercChar0),
  335.                     GOCT_SetHotKey, HOTKEY_UPONLY | 'i',
  336.                     TAG_END,
  337.                     GTIN_Number, 0,
  338.                     GTIN_MaxChars, 5,
  339.                     GT_Underscore, '_',
  340.                     GA_Disabled, FALSE,
  341.                     TAG_END,
  342.                     
  343.                 GO_ENDGRP(),
  344.                 
  345.                 GO_HORIZGRP(0,0,0), TAG_END,
  346.                 
  347.                     GO_GTBOX(INTEGER_KIND,CUSTCLIP_GID,MAXCLIPX_ID,1,(ULONG)&"M_ax:",PLACETEXT_LEFT|NG_HIGHLABEL),
  348.                     GOCT_SetHotKey, HOTKEY_LOWONLY | 'a',
  349.                     GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdAdd,300,GOT_PercChar0),
  350.                     TAG_END,
  351.                     GTIN_Number, 0,
  352.                     GTIN_MaxChars, 5,
  353.                     GT_Underscore, '_',
  354.                     GA_Disabled, FALSE,
  355.                     TAG_END,
  356.                 
  357.                     GO_GTBOX(TEXT_KIND,0,0,0,(ULONG)&"x",PLACETEXT_IN),
  358.                     TAG_END,
  359.                     GT_Underscore, '_',
  360.                     GA_Disabled, FALSE,
  361.                     TAG_END,
  362.                 
  363.                     GO_GTBOX(INTEGER_KIND,CUSTCLIP_GID,MAXCLIPY_ID,1,NULL,0),
  364.                     GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdAdd,300,GOT_PercChar0),
  365.                     GOCT_SetHotKey, HOTKEY_UPONLY | 'a',
  366.                     TAG_END,
  367.                     GTIN_Number, 0,
  368.                     GTIN_MaxChars, 5,
  369.                     GT_Underscore, '_',
  370.                     GA_Disabled, FALSE,
  371.                     TAG_END,
  372.                     
  373.                 GO_ENDGRP(),
  374.                 
  375.             GO_ENDGRP(),
  376.             
  377.             GO_VERTGRP(0,0,0), TAG_END,
  378.             
  379.                 GO_VERTGRP(0,0,0), GOCT_FitToGroup, TRUE, TAG_END,
  380.                 
  381.                     GO_HORIZGRP(0,0,0), TAG_END,
  382.  
  383.                         GO_GTBOX(INTEGER_KIND,0,WIDTH_ID,1,(ULONG)&"_Width:",PLACETEXT_LEFT|NG_HIGHLABEL),
  384.                         GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdAdd,300,GOT_PercChar0),
  385.                         GOCT_SetHotKey, HOTKEY_LOWONLY | 'w',
  386.                         TAG_END,
  387.                         GTIN_Number, 0,
  388.                         GTIN_MaxChars, 5,
  389.                         GT_Underscore, '_',
  390.                         GA_Disabled, FALSE,
  391.                         TAG_END,
  392.  
  393.                         GO_GTBOX(CHECKBOX_KIND,0,DEFWIDTH_ID,0,(ULONG)&"Defa_ult",PLACETEXT_RIGHT),
  394.                         GOCT_SetHotKey, 'u',
  395.                         TAG_END,
  396.                         GTCB_Checked, FALSE,
  397.                         GT_Underscore, '_',
  398.                         GA_Disabled, FALSE,
  399.                         TAG_END,
  400.                         
  401.                     GO_ENDGRP(),
  402.                 
  403.                     GO_HORIZGRP(0,0,0), TAG_END,
  404.  
  405.                         GO_GTBOX(INTEGER_KIND,0,HEIGHT_ID,1,(ULONG)&"_Height:",PLACETEXT_LEFT|NG_HIGHLABEL),
  406.                         GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdAdd,300,GOT_PercChar0),
  407.                         GOCT_SetHotKey, HOTKEY_LOWONLY | 'h',
  408.                         TAG_END,
  409.                         GTIN_Number, 0,
  410.                         GTIN_MaxChars, 5,
  411.                         GT_Underscore, '_',
  412.                         GA_Disabled, FALSE,
  413.                         TAG_END,
  414.                         
  415.                         GO_GTBOX(CHECKBOX_KIND,0,DEFHEIGHT_ID,0,(ULONG)&"Defau_lt",PLACETEXT_RIGHT),
  416.                         GOCT_SetHotKey, 'l',
  417.                         TAG_END,
  418.                         GTCB_Checked, FALSE,
  419.                         GT_Underscore, '_',
  420.                         GA_Disabled, FALSE,
  421.                         TAG_END,
  422.                         
  423.                     GO_ENDGRP(),
  424.                     
  425.                 GO_ENDGRP(),
  426.                 
  427.                 GO_GTBOX(CHECKBOX_KIND,0,AUTOSCROLL_ID,
  428.                     GO_WEIGHT(GO_WDIST(1,0,0,0,0,1),0,0),
  429.                     (ULONG)&"Auto_Scroll",PLACETEXT_RIGHT),
  430.                 GOCT_SetHotKey, 's',
  431.                 TAG_END,
  432.                 GTCB_Checked, TRUE,
  433.                 GT_Underscore, '_',
  434.                 GA_Disabled, FALSE,
  435.                 TAG_END,
  436.                 
  437.             GO_ENDGRP(),
  438.             
  439.         GO_ENDGRP(),
  440.  
  441.         GO_HORIZGRP(0,0,0), TAG_END,
  442.  
  443.             GO_GTBOX(TEXT_KIND, 0, SETFONTKEY_ID, 0, (ULONG)&"_Font:", PLACETEXT_LEFT|NG_HIGHLABEL),
  444.             TAG_END,
  445.             GT_Underscore, '_',
  446.             GA_Disabled, FALSE,
  447.             TAG_END,
  448.  
  449.             GO_HORIZGRP(0,0,1), GOCT_FitToGroup, TRUE, TAG_END,
  450.             
  451.                 GO_DRAWBOX(GOSD_BoopsiGad,0,SETFONT_ID,0),
  452.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  453.                 GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdSet,4,GOT_Pixels),
  454.                 GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdAdd,200,GOT_PercCharW),
  455.                 GOCT_SizeBodyWidth, GO_TSIZE(GOM_PadSet,4,GOT_Pixels),
  456.                 GOCT_SizeSpaceRight, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  457.                 GOCT_SetHotKey, HOTKEY_UPONLY | 'f',
  458.                 TAG_END,
  459.                 GODT_ExecDrawing, (ULONG)&FolderDrawing[0],
  460.                 TAG_END,
  461.             
  462.                 GO_GTBOX(STRING_KIND, 0, FONTNAME_ID, 1, NULL, 0),
  463.                 GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdAdd,400,GOT_PercCharW),
  464.                 GOCT_SizeSpaceRight, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  465.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  466.                 GOCT_SetHotKey, HOTKEY_LOWONLY | 'f',
  467.                 TAG_END,
  468.                 GTST_MaxChars, FONT_LEN, GTST_String, (ULONG)&"",
  469.                 GT_Underscore, '_',
  470.                 GA_Disabled, FALSE,
  471.                 TAG_END,
  472.  
  473.                 GO_GTBOX(INTEGER_KIND, 0, FONTSIZE_ID, 0, (ULONG)&"pnt_.", PLACETEXT_RIGHT),
  474.                 GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdAdd,400,GOT_PercChar0),
  475.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  476.                 GOCT_SetHotKey, HOTKEY_LOWONLY | '.',
  477.                 TAG_END,
  478.                 GTIN_MaxChars, 3, GTIN_Number, 0,
  479.                 GT_Underscore, '_',
  480.                 GA_Disabled, FALSE,
  481.                 TAG_END,
  482.             
  483.             GO_ENDGRP(),
  484.     
  485.             GO_EMPTYBOX(0,0,0), TAG_END,
  486.  
  487.             GO_VDRAWGRP(0,0,0),
  488.             TAG_END,
  489.             GODT_DrawStdFrame, GO_SCLPNT(SHINEPEN,0,0,63,63),
  490.             TAG_END,
  491.             
  492.                 GO_GTBOX(BUTTON_KIND, 0, OPEN_ID, 0, (ULONG)&"_Open", PLACETEXT_IN),
  493.                 GOCT_SizeSpaceAbove, GO_TSIZE(GOM_PadSet,1,GOT_Pixels),
  494.                 GOCT_SizeSpaceBelow, GO_TSIZE(GOM_PadSet,1,GOT_Pixels),
  495.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_PadSet,2,GOT_Pixels),
  496.                 GOCT_SizeSpaceRight, GO_TSIZE(GOM_PadSet,2,GOT_Pixels),
  497.                 GOCT_IgnoreMinDimens, TRUE,
  498.                 GOCT_IgnoreFinDimens, TRUE,
  499.                 GOCT_IgnoreCreation, TRUE,
  500.                 TAG_END,
  501.                 GA_Disabled, FALSE,
  502.                 GT_Underscore, '_',
  503.                 TAG_END,
  504.  
  505.                 GO_GTBOX(BUTTON_KIND, 0, MODIFY_ID, 0, (ULONG)&"M_odify", PLACETEXT_IN),
  506.                 GOCT_SizeSpaceAbove, GO_TSIZE(GOM_PadSet,1,GOT_Pixels),
  507.                 GOCT_SizeSpaceBelow, GO_TSIZE(GOM_PadSet,1,GOT_Pixels),
  508.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_PadSet,2,GOT_Pixels),
  509.                 GOCT_SizeSpaceRight, GO_TSIZE(GOM_PadSet,2,GOT_Pixels),
  510.                 GOCT_IgnoreMinDimens, TRUE,
  511.                 GOCT_IgnoreFinDimens, TRUE,
  512.                 GOCT_IgnoreCreation, TRUE,
  513.                 TAG_END,
  514.                 GA_Disabled, FALSE,
  515.                 GT_Underscore, '_',
  516.                 TAG_END,
  517.             
  518.             GO_ENDGRP(),
  519.  
  520.         GO_ENDGRP(),
  521.         
  522.     GO_ENDGRP(),
  523.  
  524.     GO_EMPTYBOX(0,0,0), TAG_END,
  525.     
  526.     GO_VERTGRP(SMALLWIN_GID,0,0),
  527.     GOCT_IgnoreMinDimens, TRUE,
  528.     GOCT_IgnoreFinDimens, TRUE,
  529.     GOCT_IgnoreCreation, TRUE,
  530.     TAG_END,
  531.     
  532.         GO_VDRAWGRP(0,0,1),
  533.         GOCT_SizeSpaceAbove, GO_TSIZE(GOM_StdSet,50,GOT_PercCharH),
  534.         GOCT_SizeSpaceBelow, GO_TSIZE(GOM_StdSet,50,GOT_PercCharH),
  535.         GOCT_SizeSpaceLeft, GO_TSIZE(GOM_StdSet,50,GOT_PercCharW),
  536.         GOCT_SizeSpaceRight, GO_TSIZE(GOM_StdSet,50,GOT_PercCharW),
  537.         TAG_END,
  538.         GODT_DrawStdFrame, GO_SCLPNT(SHINEPEN,0,0,63,63),
  539.         TAG_END,
  540.  
  541.             GO_GTBOX(CYCLE_KIND,0,DEPTH_ID,0,(ULONG)&"_Palette",PLACETEXT_ABOVE|NG_HIGHLABEL),
  542.             GOCT_SetHotKey, 'd',
  543.             TAG_END,
  544.             GTCY_Labels, (ULONG)&DepthLabels[0],
  545.             GTCY_Active, 0,
  546.             GT_Underscore, '_',
  547.             GA_Disabled, FALSE,
  548.             TAG_END,
  549.                 
  550.             GO_GTBOX(PALETTE_KIND, 0, SCRNPAL_ID, 1, NULL, 0),
  551.             GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdMax,500,GOT_PercCharW),
  552.             GOCT_SizeBodyHeight, GO_TSIZE(GOM_StdMax,200,GOT_PercCharH),
  553.             GOCT_CopyFromTSize, GO_TSIZE(GOM_StdSet,15,GOT_Pixels),
  554.             GOCT_CopyTSizeToTag, GTPA_IndicatorHeight,
  555.             GOCT_SizeUser1, GO_TSIZE(GOM_VarSet,20,GOT_PercBodyH),
  556.             GOCT_SizeUser1, GO_TSIZE(GOM_VarMin,250,GOT_PercCharH),
  557.             GOCT_SizeUser1, GO_TSIZE(GOM_VarMax,6,GOT_Pixels),
  558.             GOCT_CopyUser1ToTag, GTPA_IndicatorHeight,
  559.             GOCT_SetHotKey, 'p',
  560.             TAG_END,
  561.             GTPA_IndicatorHeight, 15,
  562.             GT_Underscore, '_',
  563.             GTPA_Color, 0,
  564.             GTPA_Depth, 2,
  565.             TAG_END,
  566.  
  567.             GO_HORIZGRP(0,0,0), TAG_END,
  568.  
  569.                 GO_GTBOX(SLIDER_KIND, FOLLOWMOUSE_GID, PALRED_ID, 1, NULL, 0),
  570.                 GOCT_SizeSpaceRight, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  571.                 GOCT_SetHotKey, 'r',
  572.                 TAG_END,
  573.                 GA_RelVerify, TRUE, GA_Immediate, TRUE,
  574.                 PGA_FREEDOM, LORIENT_HORIZ,
  575.                 GTSL_Min, 0, GTSL_Max, 15,
  576.                 GTSL_Level, 0, GTSL_LevelFormat, (ULONG)&"%02ld",
  577.                 GTSL_LevelPlace, PLACETEXT_LEFT, GTSL_MaxLevelLen, 2,
  578.                 GT_Underscore, '_',
  579.                 TAG_END,
  580.  
  581.                 GO_GTBOX(TEXT_KIND, 0, PALREDKEY_ID, 0, (ULONG)&"_R", PLACETEXT_IN|NG_HIGHLABEL),
  582.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  583.                 TAG_END,
  584.                 GTTX_Border, TRUE, // GTTX_Text, GTTX_CopyText
  585.                 GT_Underscore, '_',
  586.                 TAG_END,
  587.  
  588.             GO_ENDGRP(),
  589.             
  590.             GO_HORIZGRP(0,0,0), TAG_END,
  591.             
  592.                 GO_GTBOX(SLIDER_KIND, FOLLOWMOUSE_GID, PALGREEN_ID, 1, NULL, 0),
  593.                 GOCT_SizeSpaceRight, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  594.                 GOCT_SetHotKey, 'g',
  595.                 TAG_END,
  596.                 GA_RelVerify, TRUE, GA_Immediate, TRUE,
  597.                 PGA_FREEDOM, LORIENT_HORIZ,
  598.                 GTSL_Min, 0, GTSL_Max, 15,
  599.                 GTSL_Level, 0, GTSL_LevelFormat, (ULONG)&"%02ld",
  600.                 GTSL_LevelPlace, PLACETEXT_LEFT, GTSL_MaxLevelLen, 2,
  601.                 GT_Underscore, '_',
  602.                 TAG_END,
  603.  
  604.                 GO_GTBOX(TEXT_KIND, 0, PALGREENKEY_ID, 0, (ULONG)&"_G", PLACETEXT_IN|NG_HIGHLABEL),
  605.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  606.                 TAG_END,
  607.                 GTTX_Border, TRUE, // GTTX_Text, GTTX_CopyText
  608.                 GT_Underscore, '_',
  609.                 TAG_END,
  610.  
  611.             GO_ENDGRP(),
  612.  
  613.             GO_HORIZGRP(0,0,0), TAG_END,
  614.             
  615.                 GO_GTBOX(SLIDER_KIND, FOLLOWMOUSE_GID, PALBLUE_ID, 1, NULL, 0),
  616.                 GOCT_SizeSpaceRight, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  617.                 GOCT_SetHotKey, 'b',
  618.                 TAG_END,
  619.                 GA_RelVerify, TRUE, GA_Immediate, TRUE,
  620.                 PGA_FREEDOM, LORIENT_HORIZ,
  621.                 GTSL_Min, 0, GTSL_Max, 15,
  622.                 GTSL_Level, 0, GTSL_LevelFormat, (ULONG)&"%02ld",
  623.                 GTSL_LevelPlace, PLACETEXT_LEFT, GTSL_MaxLevelLen, 2,
  624.                 GT_Underscore, '_',
  625.                 TAG_END,
  626.  
  627.                 GO_GTBOX(TEXT_KIND, 0, PALBLUEKEY_ID, 0, (ULONG)&"_B", PLACETEXT_IN|NG_HIGHLABEL),
  628.                 GOCT_SizeSpaceLeft, GO_TSIZE(GOM_AllSet,0,GOT_Pixels),
  629.                 TAG_END,
  630.                 GTTX_Border, TRUE, // GTTX_Text, GTTX_CopyText
  631.                 GT_Underscore, '_',
  632.                 TAG_END,
  633.  
  634.             GO_ENDGRP(),
  635.             
  636.         GO_ENDGRP(),
  637.  
  638.         GO_EMPTYBOX(0,0,0), TAG_END,
  639.     
  640.         GO_VDRAWGRP(0,0,1),
  641.         GOCT_SizeSpaceAbove, GO_TSIZE(GOM_StdSet,50,GOT_PercCharH),
  642.         GOCT_SizeSpaceBelow, GO_TSIZE(GOM_StdSet,50,GOT_PercCharH),
  643.         GOCT_SizeSpaceLeft, GO_TSIZE(GOM_StdSet,50,GOT_PercCharW),
  644.         GOCT_SizeSpaceRight, GO_TSIZE(GOM_StdSet,50,GOT_PercCharW),
  645.         TAG_END,
  646.         GODT_DrawStdFrame, GO_SCLPNT(SHINEPEN,0,0,63,63),
  647.         TAG_END,
  648.  
  649.             GO_GTBOX(CYCLE_KIND,0,CURPEN_ID,0,(ULONG)&"Drawing P_ens",PLACETEXT_ABOVE|NG_HIGHLABEL),
  650.             GOCT_SetHotKey, 'e',
  651.             TAG_END,
  652.             GTCY_Labels, (ULONG)&PenLabels[0],
  653.             GTCY_Active, 0,
  654.             GT_Underscore, '_',
  655.             GA_Disabled, FALSE,
  656.             TAG_END,
  657.                 
  658.             GO_GTBOX(PALETTE_KIND, 0, PENPAL_ID, 1, NULL, 0),
  659.             GOCT_SizeBodyWidth, GO_TSIZE(GOM_StdMax,500,GOT_PercCharW),
  660.             GOCT_SizeBodyHeight, GO_TSIZE(GOM_StdMax,200,GOT_PercCharH),
  661.             GOCT_CopyFromTSize, GO_TSIZE(GOM_StdSet,15,GOT_Pixels),
  662.             GOCT_CopyTSizeToTag, GTPA_IndicatorHeight,
  663.             GOCT_SizeUser1, GO_TSIZE(GOM_VarSet,20,GOT_PercBodyH),
  664.             GOCT_SizeUser1, GO_TSIZE(GOM_VarMin,250,GOT_PercCharH),
  665.             GOCT_SizeUser1, GO_TSIZE(GOM_VarMax,6,GOT_Pixels),
  666.             GOCT_CopyUser1ToTag, GTPA_IndicatorHeight,
  667.             GOCT_SetHotKey, 'z',
  668.             TAG_END,
  669.             GTPA_IndicatorHeight, 15,
  670.             GT_Underscore, '_',
  671.             GTPA_Color, 0,
  672.             GTPA_Depth, 2,
  673.             TAG_END,
  674.             
  675.         GO_ENDGRP(),
  676.  
  677.     GO_ENDGRP(),
  678.  
  679. GO_ENDGRP(),
  680.  
  681. GO_ENDOUTLINE()
  682. };
  683.  
  684. /**
  685.  ** Handler for NewScreen window
  686.  **/
  687.  
  688. struct newscrn_globals {
  689.     struct FontRequester *font_req;
  690.     ULONG flags;
  691.     
  692.     #define NSF_MODIFY (1<<0)
  693.  
  694.     struct ModeEntry *cur_mode;
  695.     struct ColorSpec *cur_color;
  696.     UWORD *cur_pen;
  697.     struct Rectangle *cur_clip;
  698.  
  699.     struct Hook bf_hook;
  700.     UBYTE *depth_labels[SIZE_DEPTH_ARRAY+1];
  701.     UBYTE *pen_labels[SIZE_PEN_ARRAY+1];
  702.     struct ColorSpec color_specs[(1<<SIZE_DEPTH_ARRAY)+1];
  703.     struct ColorSpec orig_specs[(1<<SIZE_DEPTH_ARRAY)+1];
  704.     UWORD pens[SIZE_PEN_ARRAY+1];
  705.     UWORD cur_depth;
  706.     struct Rectangle clip;
  707.  
  708.     UBYTE vis_size[DIMEN_LEN];
  709.     UBYTE min_size[DIMEN_LEN];
  710.     UBYTE max_size[DIMEN_LEN];
  711.     UBYTE max_colors[DIMEN_LEN];
  712.     UBYTE clip_size[DIMEN_LEN];
  713. };
  714.  
  715. #define CURPUBNAME ((UBYTE *)GO_GetObjAttr(go,PUBNAME_ID,0, GTST_String,(ULONG)&""))
  716.  
  717. #define OSERR_LAST (OSERR_UNKNOWNMODE+1)
  718.  
  719. static UBYTE *open_errs[OSERR_LAST+1] = {
  720.     "None", "Monitor not available",
  721.     "Requires newer custom chips", "Not enough memory",
  722.     "Not enough chip memory", "Public name not unique",
  723.     "Don't recognize requested mode", "Unknown error"
  724. };
  725.  
  726. static void set_modify(struct GadOutline *go,struct Screen *scrn)
  727. {
  728.     struct newscrn_globals *gl;
  729.  
  730.     if(!go) return;
  731.     gl = go->go_UserData;
  732.     
  733.     if(scrn) gl->flags |= NSF_MODIFY;
  734.     else gl->flags &= ~(NSF_MODIFY);
  735.  
  736.     GO_SetObjAttrs(go,WINTAGS_ID,0,
  737.         WA_Title,scrn ? "Modify Screen" : "Open Screen", TAG_END);
  738.     GO_SetCmdAttrs(go,MODIFY_ID,0,
  739.                         GOCT_IgnoreMinDimens, !scrn,
  740.                         GOCT_IgnoreFinDimens, !scrn,
  741.                         GOCT_IgnoreCreation, !scrn,
  742.                         TAG_END);
  743.     GO_SetCmdAttrs(go,OPEN_ID,0,
  744.                         GOCT_IgnoreMinDimens, scrn,
  745.                         GOCT_IgnoreFinDimens, scrn,
  746.                         GOCT_IgnoreCreation, scrn,
  747.                         TAG_END);
  748.     GO_AttachHotKey(go,'o',0);
  749.     GO_AttachHotKey(go,'o',scrn ? MODIFY_ID : OPEN_ID);
  750. }
  751.  
  752. UBYTE *strdup_track(void *track,UBYTE *str)
  753. {
  754.     UBYTE *dup;
  755.  
  756.     if(!str) return NULL;
  757.  
  758.     dup = AllocScrnTrackMem(track,strlen(str)+2);
  759.     if(dup != NULL) strcpy(dup,str);
  760.     return dup;
  761. }
  762.  
  763. void mem_err(struct GadOutline *go,void *track)
  764. {
  765.     if(track) FreeScrnTrack(track);
  766.     GO_ShowError(go,GO_MAKEERR(GOTYPE_FAIL,0),NULL,"Not enough memory.");
  767. }
  768.  
  769. static struct Window *open_window(struct GadOutline *go,ULONG tags,...)
  770. {
  771.     // Window must be unlocked.
  772.     UnlockGadOutline(go);
  773.  
  774.     // Tell GadOutline library to be quiet.
  775.     UpdateGadOutline(go,GOA_ErrorReportLevel,0,TAG_END);
  776.  
  777.     // And start out trying a full-size window.
  778.     GO_SetCmdGrpAttrs(go,GO_CMDID(SMALLWIN_GID,0),0,
  779.                         GOCT_IgnoreMinDimens, FALSE,
  780.                         GOCT_IgnoreFinDimens, FALSE,
  781.                         GOCT_IgnoreCreation, FALSE,
  782.                         TAG_END);
  783.  
  784.     if( !GO_OpenWindowA(go,(struct TagItem *)&tags) || go->go_LastReqReturn ) {
  785.         GO_SetCmdGrpAttrs(go,GO_CMDID(SMALLWIN_GID,0),0,
  786.                             GOCT_IgnoreMinDimens, TRUE,
  787.                             GOCT_IgnoreFinDimens, TRUE,
  788.                             GOCT_IgnoreCreation, TRUE,
  789.                             TAG_END);
  790.  
  791.         UpdateGadOutline(go,GOA_ErrorReportLevel,STD_REPORT_LEVEL,TAG_END);
  792.         
  793.         if( !GO_OpenWindowA(go,(struct TagItem *)&tags) || go->go_LastReqReturn ) {
  794.             return NULL;
  795.         }
  796.     }
  797.  
  798.     UpdateGadOutline(go,GOA_ErrorReportLevel,STD_REPORT_LEVEL,TAG_END);
  799.     return go->go_Window;
  800. }
  801.  
  802. static struct Screen *open_screen(struct GadOutline *go)
  803. {
  804.     void *track;
  805.     struct Screen *scrn;
  806.     struct newscrn_globals *gl;
  807.     struct TextAttr *ta;
  808.     UBYTE *title;
  809.     LONG error;
  810.     UBYTE depth;
  811.  
  812.     if( !(track = AllocScrnTrack()) ) {
  813.         mem_err(go,track);
  814.         return NULL;
  815.     }
  816.  
  817.     if( !(ta=AllocScrnTrackMem(track,sizeof(struct TextAttr))) ) {
  818.         mem_err(go,track);
  819.         return NULL;
  820.     }
  821.  
  822.     if( !(ta->ta_Name=strdup_track(track,
  823.             (UBYTE *)GO_GetObjAttr(go,FONTNAME_ID,0, GTST_String,NULL))) ) {
  824.         mem_err(go,track);
  825.         return NULL;
  826.     }
  827.  
  828.     ta->ta_YSize = GO_GetObjAttr(go,FONTSIZE_ID,0, GTIN_Number,0);
  829.     ta->ta_Style = FS_NORMAL;
  830.     ta->ta_Flags = FPF_DISKFONT;
  831.     depth = GO_GetObjAttr(go,DEPTH_ID,0, GTCY_Active,0)+1;
  832.  
  833.     if(!go) return NULL;
  834.     gl = go->go_UserData;
  835.     
  836.     gl->color_specs[1<<depth].ColorIndex = -1;
  837.     
  838.     // Make sure the font is available in RAM.
  839.     {
  840.         struct TextFont *font;
  841.         
  842.         if(font = OpenDiskFont(ta)) CloseFont(font);
  843.     }
  844.     
  845.     title = (UBYTE *)GO_GetObjAttr(go,TITLE_ID,0, GTST_String,NULL);
  846.     if( !title || title[0] == 0 ) {
  847.         title = (UBYTE *)GO_GetObjAttr(go,PUBNAME_ID,0, GTST_String,NULL);
  848.     }
  849.  
  850.     scrn = OpenScreenTags(NULL,
  851.         SA_Width, GO_GetObjAttr(go,WIDTH_ID,0, GTIN_Number,0),
  852.         SA_Height, GO_GetObjAttr(go,HEIGHT_ID,0, GTIN_Number,0),
  853.         SA_Depth, GO_GetObjAttr(go,DEPTH_ID,0, GTCY_Active,0)+1,
  854.         SA_Title, strdup_track(track,title),
  855.         SA_Colors, &gl->color_specs,
  856.         SA_Font, ta,
  857.         SA_PubName, GO_GetObjAttr(go,PUBNAME_ID,0, GTST_String,NULL),
  858.         SA_DisplayID, gl->cur_mode ? gl->cur_mode->mode : 0,
  859.         SA_DClip, gl->cur_clip,
  860.         SA_Pens, &gl->pens,
  861.         SA_FullPalette, TRUE,
  862.         SA_AutoScroll, GO_GetObjAttr(go,AUTOSCROLL_ID,0, GTCB_Checked,TRUE),
  863.         SA_ErrorCode, &error,
  864.         TAG_END);
  865.     
  866.     gl->color_specs[1<<depth].ColorIndex = 1<<depth;
  867.     gl->orig_specs[1<<SIZE_DEPTH_ARRAY].ColorIndex = 
  868.         gl->color_specs[1<<SIZE_DEPTH_ARRAY].ColorIndex = -1;
  869.  
  870.     if(!scrn) {
  871.         FreeScrnTrack(track);
  872.         GO_ShowError(go,GO_MAKEERR(GOTYPE_FAIL,0),NULL,
  873.             "Error #%ld opening screen:\n%ls.",
  874.             error, open_errs[(error > OSERR_LAST) ? OSERR_LAST : error]);
  875.     } else {
  876.         AddScrnTrack(track,scrn);
  877.         
  878.         // We want to return with this screen public, but locked.  If someone
  879.         // somehow manages to swipe the screen out from under us... Oh well.
  880.         Forbid();
  881.         PubScreenStatus(scrn,0);
  882.         scrn = LockPubScreen(CURPUBNAME);
  883.         Permit();
  884.     }
  885.  
  886.     return scrn;
  887. }
  888.  
  889. static void update_size(struct GadOutline *go)
  890. {
  891.     struct newscrn_globals *gl;
  892.  
  893.     if(!go) return;
  894.     gl = go->go_UserData;
  895.     
  896.     if(GO_GetObjAttr(go,DEFWIDTH_ID,0, GTCB_Checked,TRUE)) {
  897.         GO_SetObjAttrs(go,WIDTH_ID,0,
  898.             GTIN_Number, (gl->cur_clip)
  899.                              ? (gl->cur_clip->MaxX - gl->cur_clip->MinX + 1)
  900.                              : 0,
  901.             GA_Disabled, TRUE,
  902.             TAG_END);
  903.     } else {
  904.         GO_SetObjAttrs(go,WIDTH_ID,0,GA_Disabled,FALSE,TAG_END);
  905.     }
  906.  
  907.     if(GO_GetObjAttr(go,DEFHEIGHT_ID,0, GTCB_Checked,TRUE)) {
  908.         GO_SetObjAttrs(go,HEIGHT_ID,0,
  909.             GTIN_Number, (gl->cur_clip)
  910.                              ? (gl->cur_clip->MaxY - gl->cur_clip->MinY + 1)
  911.                              : 0,
  912.             GA_Disabled, TRUE,
  913.             TAG_END);
  914.     } else {
  915.         GO_SetObjAttrs(go,HEIGHT_ID,0,GA_Disabled,FALSE,TAG_END);
  916.     }
  917. }
  918.  
  919. static BOOL comp_clip(struct Rectangle *rect1,struct Rectangle *rect2)
  920. {
  921.     if( rect1->MinX == rect2->MinX
  922.         && rect1->MinY == rect2->MinY
  923.         && rect1->MaxX == rect2->MaxX
  924.         && rect1->MaxY == rect2->MaxY ) return TRUE;
  925.     
  926.     return FALSE;
  927. }
  928.  
  929. static void update_clipping(struct GadOutline *go)
  930. {
  931.     struct newscrn_globals *gl;
  932.     ULONG new_clip;
  933.  
  934.     if(!go) return;
  935.     gl = go->go_UserData;
  936.     
  937.     new_clip = GO_GetObjAttr(go,STDCLIP_ID,0,GTCY_Active,CLIP_CUSTOM);
  938.  
  939.     gl->cur_clip = NULL;
  940.  
  941.     if(new_clip == CLIP_CUSTOM) {
  942.         GO_SetObjGrpAttrs(go,GO_CMDID(CUSTCLIP_GID,0),0,GA_Disabled,FALSE,TAG_END);
  943.         gl->cur_clip = &gl->clip;
  944.     } else {
  945.         GO_SetObjGrpAttrs(go,GO_CMDID(CUSTCLIP_GID,0),0,GA_Disabled,TRUE,TAG_END);
  946.         
  947.         if(gl->cur_mode) {
  948.             if(new_clip == CLIP_MINIMUM) gl->cur_clip = &gl->cur_mode->dims.Nominal;
  949.             else if(new_clip == CLIP_STANDARD) gl->cur_clip = &gl->cur_mode->dims.StdOScan;
  950.             else if(new_clip == CLIP_TEXT) gl->cur_clip = &gl->cur_mode->dims.TxtOScan;
  951.             else if(new_clip == CLIP_VIDEO) gl->cur_clip = &gl->cur_mode->dims.VideoOScan;
  952.             else if(new_clip == CLIP_MAXIMUM) gl->cur_clip = &gl->cur_mode->dims.MaxOScan;
  953.         }
  954.     }
  955.  
  956.     if(gl->cur_clip) {
  957.         sprintf(&gl->clip_size[0],"(%ld,%ld) - (%ld,%ld)",
  958.             gl->cur_clip->MinX,gl->cur_clip->MinY,gl->cur_clip->MaxX,gl->cur_clip->MaxY);
  959.         /**
  960.         if( GO_GetObjAttr(go,WIDTH_ID,0, GTIN_Number,0)
  961.             == (gl->cur_clip->MaxX - gl->cur_clip->MinX + 1) ) {
  962.             GO_SetObjAttrs(go,DEFWIDTH_ID,0, GTCB_Checked,TRUE,TAG_END);
  963.         } else {
  964.             GO_SetObjAttrs(go,DEFWIDTH_ID,0, GTCB_Checked,FALSE,TAG_END);
  965.         }
  966.         if( GO_GetObjAttr(go,HEIGHT_ID,0, GTIN_Number,0)
  967.             == (gl->cur_clip->MaxY - gl->cur_clip->MinY + 1) ) {
  968.             GO_SetObjAttrs(go,DEFHEIGHT_ID,0, GTCB_Checked,TRUE,TAG_END);
  969.         } else {
  970.             GO_SetObjAttrs(go,DEFHEIGHT_ID,0, GTCB_Checked,FALSE,TAG_END);
  971.         }
  972.         **/
  973.     } else {
  974.         gl->clip_size[0] = 0;
  975.     }
  976.     
  977.     update_size(go);
  978. }
  979.  
  980. static void redraw_clipping(struct GadOutline *go)
  981. {
  982.     struct newscrn_globals *gl;
  983.  
  984.     if(!go) return;
  985.     gl = go->go_UserData;
  986.     
  987.     update_clipping(go);
  988.     
  989.     GO_SetObjAttrs(go,MODEINFO_ID,0,
  990.         GOUS_ClippingSize, &gl->clip_size[0],
  991.         TAG_END);
  992. }
  993.  
  994. static void update_pen(struct GadOutline *go)
  995. {
  996.     struct newscrn_globals *gl;
  997.     ULONG new_pen;
  998.  
  999.     if(!go) return;
  1000.     gl = go->go_UserData;
  1001.     
  1002.     new_pen = GO_GetObjAttr(go,CURPEN_ID,0,GTCY_Active,0);
  1003.     if(new_pen >= (1<<SIZE_PEN_ARRAY)) new_pen = (1<<SIZE_PEN_ARRAY)-1;
  1004.  
  1005.     gl->cur_pen = &gl->pens[new_pen];
  1006.     GO_SetObjAttrs(go,PENPAL_ID,0,
  1007.         GTPA_Color,gl->pens[new_pen]&((1<<gl->cur_depth)-1),TAG_END);
  1008. }
  1009.  
  1010. static void update_color(struct GadOutline *go)
  1011. {
  1012.     struct newscrn_globals *gl;
  1013.     ULONG new_color;
  1014.  
  1015.     if(!go) return;
  1016.     gl = go->go_UserData;
  1017.     
  1018.     new_color = GO_GetObjAttr(go,SCRNPAL_ID,0,GTPA_Color,0);
  1019.     if(new_color >= (1<<gl->cur_depth)) {
  1020.         new_color &= (1<<gl->cur_depth)-1;
  1021.         GO_SetObjAttrs(go,SCRNPAL_ID,0,GTPA_Color,new_color,TAG_END);
  1022.     }
  1023.     if(new_color >= (1<<SIZE_DEPTH_ARRAY)) new_color = (1<<SIZE_DEPTH_ARRAY)-1;
  1024.  
  1025.     gl->cur_color = &gl->color_specs[new_color];
  1026.     GO_SetObjAttrs(go,PALRED_ID,0,GTSL_Level,gl->cur_color->Red,TAG_END);
  1027.     GO_SetObjAttrs(go,PALGREEN_ID,0,GTSL_Level,gl->cur_color->Green,TAG_END);
  1028.     GO_SetObjAttrs(go,PALBLUE_ID,0,GTSL_Level,gl->cur_color->Blue,TAG_END);
  1029. }
  1030.  
  1031. static void update_depth(struct GadOutline *go)
  1032. {
  1033.     struct newscrn_globals *gl;
  1034.     ULONG new_depth;
  1035.     
  1036.     if(!go) return;
  1037.     gl = go->go_UserData;
  1038.     
  1039.     new_depth = GO_GetObjAttr(go,DEPTH_ID,0,GTCY_Active,0) + 1;
  1040.     if( new_depth < gl->cur_depth
  1041.         || new_depth != GO_GetObjAttr(go,SCRNPAL_ID,0,GTPA_Depth,1) ) {
  1042.  
  1043.         gl->cur_depth = new_depth;
  1044.         update_color(go);
  1045.         update_pen(go);
  1046.         GO_SetObjAttrs(go,SCRNPAL_ID,0,GTPA_Depth,gl->cur_depth,TAG_END);
  1047.         GO_SetObjAttrs(go,PENPAL_ID,0,GTPA_Depth,gl->cur_depth,TAG_END);
  1048.         RebuildGadOutline(go,TAG_END);
  1049.     }
  1050. }
  1051.  
  1052. static void update_mode(struct GadOutline *go)
  1053. {
  1054.     struct newscrn_globals *gl;
  1055.     struct ModeEntry *curmode;
  1056.     ULONG i;
  1057.  
  1058.     if(!go) return;
  1059.     gl = go->go_UserData;
  1060.     
  1061.     gl->cur_mode = curmode =
  1062.         num_to_node(&ScreenModeList,GO_GetObjAttr(go,MODELIST_ID,0,GTLV_Selected,-1));
  1063.     if(curmode) {
  1064.         sprintf(&gl->vis_size[0],"%5ld x %5ld",
  1065.             curmode->dims.StdOScan.MaxX - curmode->dims.StdOScan.MinX + 1,
  1066.             curmode->dims.StdOScan.MaxY - curmode->dims.StdOScan.MinY + 1);
  1067.         sprintf(&gl->min_size[0],"%5ld x %5ld",
  1068.             curmode->dims.Nominal.MaxX - curmode->dims.Nominal.MinX + 1,
  1069.             curmode->dims.Nominal.MaxY - curmode->dims.Nominal.MinY + 1);
  1070.         sprintf(&gl->max_size[0],"%5ld x %5ld",
  1071.             curmode->dims.MaxRasterWidth,curmode->dims.MaxRasterHeight);
  1072.         sprintf(&gl->max_colors[0],"%3ld",1<<curmode->dims.MaxDepth);
  1073.         for(i=0;DepthLabels[i] && i < curmode->dims.MaxDepth;i++) {
  1074.             gl->depth_labels[i] = DepthLabels[i];
  1075.         }
  1076.         gl->depth_labels[i] = NULL;
  1077.     } else {
  1078.         gl->vis_size[0] = gl->min_size[0] =
  1079.             gl->max_size[0] = gl->max_colors[0] = 0;
  1080.     }
  1081.     
  1082.     update_depth(go);
  1083.     update_clipping(go);
  1084.  
  1085.     GO_SetObjAttrs(go,MODEINFO_ID,0,
  1086.         GOUS_VisibleSize, &gl->vis_size[0],
  1087.         GOUS_MinimumSize, &gl->min_size[0],
  1088.         GOUS_MaximumSize, &gl->max_size[0],
  1089.         GOUS_MaximumColors, &gl->max_colors[0],
  1090.         GOUS_ClippingSize, &gl->clip_size[0],
  1091.         TAG_END);
  1092.     GO_SetObjAttrs(go,DEPTH_ID,0, GTCY_Labels,&gl->depth_labels[0],TAG_END);
  1093. }
  1094.  
  1095. static void *GetVPortTag(struct ColorMap *cm,ULONG vtag)
  1096. {
  1097.     struct TagItem tags[] = {
  1098.         { 0, 0 }, { VTAG_END_CM, 0 }
  1099.     };
  1100.     
  1101.     tags[0].ti_Tag = vtag;
  1102.     if(VideoControl(cm,&tags[0])==NULL) {
  1103.         return (void *)tags[0].ti_Data;
  1104.     }
  1105.     return NULL;
  1106. }
  1107.  
  1108. static void get_colors(struct GadOutline *go,struct Screen *scrn)
  1109. {
  1110.     struct newscrn_globals *gl;
  1111.     struct ColorMap *cm;
  1112.     ULONG i;
  1113.  
  1114.     if(!go) return;
  1115.     gl = go->go_UserData;
  1116.     
  1117.     // --------------------------------
  1118.     // Set up default palette
  1119.     // --------------------------------
  1120.     
  1121.     cm = GetColorMap(1<<SIZE_DEPTH_ARRAY);
  1122.         
  1123.     for(i=0;i<(1<<SIZE_DEPTH_ARRAY);i++) {
  1124.         UWORD color;
  1125.  
  1126.         if(scrn && i < (1<<scrn->BitMap.Depth))
  1127.             color = GetRGB4(scrn->ViewPort.ColorMap,i);
  1128.         else if(cm)
  1129.             color = GetRGB4(cm,i);
  1130.         else
  1131.             color = 0;
  1132.         gl->orig_specs[i].ColorIndex = gl->color_specs[i].ColorIndex = i;
  1133.         gl->orig_specs[i].Red = gl->color_specs[i].Red = (color>>8)&0xF;
  1134.         gl->orig_specs[i].Green = gl->color_specs[i].Green = (color>>4)&0xF;
  1135.         gl->orig_specs[i].Blue = gl->color_specs[i].Blue = (color>>0)&0xF;
  1136.     }
  1137.  
  1138.     gl->orig_specs[1<<SIZE_DEPTH_ARRAY].ColorIndex = 
  1139.         gl->color_specs[1<<SIZE_DEPTH_ARRAY].ColorIndex = -1;
  1140.  
  1141.     if(cm) FreeColorMap(cm);
  1142. }
  1143.  
  1144. static void update_from_screen(struct GadOutline *go,UBYTE *name,struct Screen *scrn)
  1145. {
  1146.     struct newscrn_globals *gl;
  1147.     struct ModeEntry *scrn_entry = NULL;
  1148.     struct ViewPortExtra *vpe;
  1149.     ULONG scrn_mode;
  1150.     UWORD num_pens;
  1151.     
  1152.     if(!go) return;
  1153.     
  1154.     if(!(gl = go->go_UserData)) return;
  1155.  
  1156.     // --------------------------------
  1157.     // Set up default palette
  1158.     // --------------------------------
  1159.     
  1160.     get_colors(go,scrn);
  1161.  
  1162.     // --------------------------------
  1163.     // Set up default display mode.
  1164.     // --------------------------------
  1165.     
  1166.     scrn_mode = INVALID_ID;
  1167.     if(scrn) scrn_mode = GetVPModeID(&scrn->ViewPort);
  1168.  
  1169.     if(scrn_mode != INVALID_ID) {
  1170.         scrn_entry = head_node(&ScreenModeList);
  1171.         while(scrn_entry && scrn_mode != scrn_entry->mode) {
  1172.             scrn_entry = next_node(scrn_entry);
  1173.         }
  1174.     }
  1175.     if(scrn_entry) gl->cur_mode = scrn_entry;
  1176.     else gl->cur_mode = head_node(&ScreenModeList);
  1177.  
  1178.     GO_SetObjAttrs(go,MODELIST_ID,0, GTLV_Labels,&ScreenModeList,TAG_END);
  1179.     if(scrn_entry) {
  1180.         GO_SetObjAttrs(go,MODELIST_ID,0, 
  1181.             GTLV_Selected,node_to_num(&ScreenModeList,scrn_entry),TAG_END);
  1182.     }
  1183.  
  1184.     // --------------------------------
  1185.     // Set up default pens.
  1186.     // --------------------------------
  1187.     
  1188.     num_pens = SIZE_PEN_ARRAY;
  1189.     if(scrn) {
  1190.         struct DrawInfo *di;
  1191.         
  1192.         if( (di=GetScreenDrawInfo(scrn)) ) {
  1193.             if(di->dri_Version >= 1) {
  1194.                 UWORD num_pens = di->dri_NumPens;
  1195.         
  1196.                 if(num_pens > SIZE_PEN_ARRAY) num_pens = SIZE_PEN_ARRAY;
  1197.                 memcpy(&gl->pens[0],di->dri_Pens,num_pens*sizeof(UWORD));
  1198.             }
  1199.         }
  1200.     }
  1201.  
  1202.     if(num_pens < 2) num_pens = 2;
  1203.     gl->pens[num_pens] = 0xFFFF;
  1204.     memcpy(&gl->pen_labels[0],&PenLabels[0],num_pens*sizeof(UBYTE *));
  1205.     gl->pen_labels[num_pens] = NULL;
  1206.     GO_SetObjAttrs(go,CURPEN_ID,0, GTCY_Labels,&gl->pen_labels[0],TAG_END);
  1207.  
  1208.     // --------------------------------
  1209.     // Set up default clipping.
  1210.     // --------------------------------
  1211.     
  1212.     if( scrn && (vpe = GetVPortTag(scrn->ViewPort.ColorMap,VTAG_VIEWPORTEXTRA_GET)) ) {
  1213.         gl->clip.MinX = vpe->DisplayClip.MinX;
  1214.         gl->clip.MinY = vpe->DisplayClip.MinY;
  1215.         gl->clip.MaxX = vpe->DisplayClip.MaxX;
  1216.         gl->clip.MaxY = vpe->DisplayClip.MaxY;
  1217.         if(gl->cur_mode) {
  1218.             if(comp_clip(&vpe->DisplayClip,&gl->cur_mode->dims.StdOScan)) {
  1219.                 GO_SetObjAttrs(go,STDCLIP_ID,0,GTCY_Active,CLIP_STANDARD,TAG_END);
  1220.             } else if(comp_clip(&vpe->DisplayClip,&gl->cur_mode->dims.TxtOScan)) {
  1221.                 GO_SetObjAttrs(go,STDCLIP_ID,0,GTCY_Active,CLIP_TEXT,TAG_END);
  1222.             } else if(comp_clip(&vpe->DisplayClip,&gl->cur_mode->dims.VideoOScan)) {
  1223.                 GO_SetObjAttrs(go,STDCLIP_ID,0,GTCY_Active,CLIP_VIDEO,TAG_END);
  1224.             } else if(comp_clip(&vpe->DisplayClip,&gl->cur_mode->dims.Nominal)) {
  1225.                 GO_SetObjAttrs(go,STDCLIP_ID,0,GTCY_Active,CLIP_MINIMUM,TAG_END);
  1226.             } else if(comp_clip(&vpe->DisplayClip,&gl->cur_mode->dims.MaxOScan)) {
  1227.                 GO_SetObjAttrs(go,STDCLIP_ID,0,GTCY_Active,CLIP_MAXIMUM,TAG_END);
  1228.             } else {
  1229.                 GO_SetObjAttrs(go,STDCLIP_ID,0,GTCY_Active,CLIP_CUSTOM,TAG_END);
  1230.             }
  1231.         } else {
  1232.             GO_SetObjAttrs(go,STDCLIP_ID,0,GTCY_Active,CLIP_CUSTOM,TAG_END);
  1233.         }
  1234.     } else if(gl->cur_mode) {
  1235.         gl->clip.MinX = gl->cur_mode->dims.StdOScan.MinX;
  1236.         gl->clip.MinY = gl->cur_mode->dims.StdOScan.MinY;
  1237.         gl->clip.MaxX = gl->cur_mode->dims.StdOScan.MaxX;
  1238.         gl->clip.MaxY = gl->cur_mode->dims.StdOScan.MaxY;
  1239.         GO_SetObjAttrs(go,STDCLIP_ID,0,GTCY_Active,CLIP_STANDARD,TAG_END);
  1240.     } else {
  1241.         gl->clip.MinX = gl->clip.MinY = 0;
  1242.         gl->clip.MaxX = gl->clip.MaxY = 0;
  1243.         GO_SetObjAttrs(go,STDCLIP_ID,0,GTCY_Active,CLIP_STANDARD,TAG_END);
  1244.     }
  1245.  
  1246.     GO_SetObjAttrs(go,MINCLIPX_ID,0, GTIN_Number,gl->clip.MinX,TAG_END);
  1247.     GO_SetObjAttrs(go,MINCLIPY_ID,0, GTIN_Number,gl->clip.MinY,TAG_END);
  1248.     GO_SetObjAttrs(go,MAXCLIPX_ID,0, GTIN_Number,gl->clip.MaxX,TAG_END);
  1249.     GO_SetObjAttrs(go,MAXCLIPY_ID,0, GTIN_Number,gl->clip.MaxY,TAG_END);
  1250.     
  1251.     // --------------------------------
  1252.     // Set up default screen size.
  1253.     // --------------------------------
  1254.     
  1255.     if(scrn) {
  1256.         GO_SetObjAttrs(go,WIDTH_ID,0, GTIN_Number,scrn->Width,TAG_END);
  1257.         GO_SetObjAttrs(go,HEIGHT_ID,0, GTIN_Number,scrn->Height,TAG_END);
  1258.     } else {
  1259.         GO_SetObjAttrs(go,WIDTH_ID,0,
  1260.             GTIN_Number,gl->clip.MaxX - gl->clip.MinX + 1,TAG_END);
  1261.         GO_SetObjAttrs(go,HEIGHT_ID,0,
  1262.             GTIN_Number,gl->clip.MaxY - gl->clip.MinY + 1,TAG_END);
  1263.     }
  1264.     GO_SetObjAttrs(go,DEFWIDTH_ID,0,GTCB_Checked,FALSE,TAG_END);
  1265.     GO_SetObjAttrs(go,DEFHEIGHT_ID,0, GTCB_Checked,FALSE,TAG_END);
  1266.  
  1267.     // --------------------------------
  1268.     // Set up other defaults.
  1269.     // --------------------------------
  1270.     
  1271.     if(scrn) {
  1272.         if(name) {
  1273.             GO_SetObjAttrs(go,TITLE_ID,0, GTST_String,scrn->DefaultTitle,TAG_END);
  1274.             GO_SetObjAttrs(go,PUBNAME_ID,0, GTST_String,name,TAG_END);
  1275.         }
  1276.  
  1277.         if( (scrn->Flags&AUTOSCROLL) ) {
  1278.             GO_SetObjAttrs(go,AUTOSCROLL_ID,0, GTCB_Checked,TRUE,TAG_END);
  1279.         } else {
  1280.             GO_SetObjAttrs(go,AUTOSCROLL_ID,0, GTCB_Checked,FALSE,TAG_END);
  1281.         }
  1282.  
  1283.         if(scrn->Font) {
  1284.             GO_SetObjAttrs(go,FONTNAME_ID,0, 
  1285.                 GTST_String,scrn->Font->ta_Name,TAG_END);
  1286.             GO_SetObjAttrs(go,FONTSIZE_ID,0, 
  1287.                 GTIN_Number,scrn->Font->ta_YSize,TAG_END);
  1288.         }
  1289.  
  1290.         GO_SetObjAttrs(go,DEPTH_ID,0, GTCY_Active,scrn->BitMap.Depth-1,TAG_END);
  1291.     }
  1292.  
  1293.     gl->cur_depth = 0xFF;
  1294.     update_mode(go);
  1295.     update_depth(go);
  1296.     update_color(go);
  1297.     update_pen(go);
  1298.     update_clipping(go);
  1299.  
  1300.     if(gl->cur_clip) {
  1301.         if( GO_GetObjAttr(go,WIDTH_ID,0, GTIN_Number,0)
  1302.             == (gl->cur_clip->MaxX - gl->cur_clip->MinX + 1) ) {
  1303.             GO_SetObjAttrs(go,DEFWIDTH_ID,0, GTCB_Checked,TRUE,TAG_END);
  1304.         } else {
  1305.             GO_SetObjAttrs(go,DEFWIDTH_ID,0, GTCB_Checked,FALSE,TAG_END);
  1306.         }
  1307.         if( GO_GetObjAttr(go,HEIGHT_ID,0, GTIN_Number,0)
  1308.             == (gl->cur_clip->MaxY - gl->cur_clip->MinY + 1) ) {
  1309.             GO_SetObjAttrs(go,DEFHEIGHT_ID,0, GTCB_Checked,TRUE,TAG_END);
  1310.         } else {
  1311.             GO_SetObjAttrs(go,DEFHEIGHT_ID,0, GTCB_Checked,FALSE,TAG_END);
  1312.         }
  1313.     }
  1314.  
  1315.     update_size(go);
  1316. }
  1317.  
  1318. static ULONG __saveds __interrupt
  1319. newscrn_handler(struct GadOutline *go, ULONG command, struct GOIMsg *msg)
  1320. {
  1321.     struct newscrn_globals *gl;
  1322.     struct Gadget *gadget;
  1323.     ULONG class;
  1324.     UWORD code;
  1325.     UWORD qual;
  1326.  
  1327.     if(go == NULL) return HNDRES_CLOSEWIN;
  1328.  
  1329.     if( !(gl = (struct newscrn_globals *)go->go_UserData) ) {
  1330.         return HNDRES_CLOSEWIN;
  1331.     }
  1332.  
  1333.     if(command == HNDCMD_IDCMPMSG) {
  1334.         if( msg ) {
  1335.             class = msg->StdIMsg.Class;
  1336.             code = msg->StdIMsg.Code;
  1337.             qual = msg->StdIMsg.Qualifier;
  1338.             gadget = (struct Gadget *)msg->StdIMsg.IAddress;
  1339.         } else {
  1340.             return HNDRES_CLOSEWIN;
  1341.         }
  1342.     } else if(command == HNDCMD_SHUTDOWN) {
  1343.         if(go == (struct GadOutline *)msg) {
  1344.             if( (gl->flags&NSF_MODIFY) && go->go_Screen ) {
  1345.                 ULONG i;
  1346.                 
  1347.                 for(i=0;i<(1<<go->go_Screen->BitMap.Depth);i++) {
  1348.                     SetRGB4(&go->go_Screen->ViewPort,
  1349.                         gl->orig_specs[i].ColorIndex,
  1350.                         gl->orig_specs[i].Red&0xF,
  1351.                         gl->orig_specs[i].Green&0xF,
  1352.                         gl->orig_specs[i].Blue&0xF);
  1353.                 }
  1354.             }
  1355.             DestroyNewScrn(go);
  1356.         }
  1357.         return HNDRES_NORMAL;
  1358.     } else if(command == HNDCMD_MOVEWIN && !(gl->flags&NSF_MODIFY)) {
  1359.         if(msg) {
  1360.             if( !open_window(go,WA_CustomScreen,(struct Window *)msg,TAG_END) ) {
  1361.                 return HNDRES_CLOSEWIN;
  1362.             }
  1363.             return HNDRES_NORMAL;
  1364.         } else return HNDRES_CLOSEWIN;
  1365.     } else if(command == HNDCMD_HIDEWIN && !(gl->flags&NSF_MODIFY)) {
  1366.         UnlockGadOutline(go);   // Window must be unlocked.
  1367.         GO_CloseScreen(go);
  1368.         return HNDRES_NORMAL;
  1369.     } else if(command == HNDCMD_LOCK) {
  1370.         LockGadOutline(go);
  1371.         return HNDRES_NORMAL;
  1372.     } else if(command == HNDCMD_UNLOCK) {
  1373.         UnlockGadOutline(go);
  1374.         return HNDRES_NORMAL;
  1375.     } else {
  1376.         return HNDRES_NORMAL;
  1377.     }
  1378.  
  1379.     if(class == IDCMP_MOUSEMOVE && go->go_ActCmdInfo) {
  1380.         gadget = go->go_ActCmdInfo->ci_Object;
  1381.         if( (GETGRPID(go->go_ActCmdInfo->ci_CmdID)&FOLLOWMOUSE_GID) ) {
  1382.             class = IDCMP_GADGETUP;
  1383.         }
  1384.     }
  1385.  
  1386.     switch (class) {
  1387.  
  1388.         case IDCMP_CLOSEWINDOW:
  1389.         {
  1390.             return HNDRES_CLOSEWIN;
  1391.         } break;
  1392.  
  1393.         case IDCMP_REFRESHWINDOW:
  1394.         {
  1395.             GO_BeginRefresh(go);
  1396.             GO_EndRefresh(go, TRUE);
  1397.         } break;
  1398.  
  1399.         case IDCMP_GADGETUP:
  1400.         {
  1401.         
  1402.             switch(gadget->GadgetID) {
  1403.             
  1404.                 case MODELIST_ID:
  1405.                 {
  1406.                     update_mode(go);
  1407.                 } break;
  1408.  
  1409.                 case STDCLIP_ID:
  1410.                 case MAXCLIPX_ID:
  1411.                 case MAXCLIPY_ID:
  1412.                 case MINCLIPX_ID:
  1413.                 case MINCLIPY_ID:
  1414.                 {
  1415.                     gl->clip.MinX = GO_GetObjAttr(go,MINCLIPX_ID,0, GTIN_Number,0);
  1416.                     gl->clip.MinY = GO_GetObjAttr(go,MINCLIPY_ID,0, GTIN_Number,0);
  1417.                     gl->clip.MaxX = GO_GetObjAttr(go,MAXCLIPX_ID,0, GTIN_Number,0);
  1418.                     gl->clip.MaxY = GO_GetObjAttr(go,MAXCLIPY_ID,0, GTIN_Number,0);
  1419.                     redraw_clipping(go);
  1420.                 } break;
  1421.  
  1422.                 case DEFWIDTH_ID:
  1423.                 case DEFHEIGHT_ID:
  1424.                 {
  1425.                     update_size(go);
  1426.                 } break;
  1427.  
  1428.                 case SETFONT_ID:
  1429.                 {
  1430.                     if( AslRequestTags(gl->font_req,
  1431.                         ASL_FontName,
  1432.                             GO_GetObjAttr(go,FONTNAME_ID,0, GTST_String,(ULONG)&""),
  1433.                         ASL_FontHeight,
  1434.                             GO_GetObjAttr(go,FONTSIZE_ID,0, GTIN_Number,0),
  1435.                         ASL_Window, go->go_Window,
  1436.                         TAG_END) ) {
  1437.                     
  1438.                         GO_SetObjAttrs(go,FONTNAME_ID,0,
  1439.                             GTST_String,gl->font_req->fo_Attr.ta_Name,
  1440.                             TAG_END);
  1441.                         GO_SetObjAttrs(go,FONTSIZE_ID,0,
  1442.                             GTIN_Number,gl->font_req->fo_Attr.ta_YSize,
  1443.                             TAG_END);
  1444.                                 
  1445.                     }
  1446.                 } break;
  1447.  
  1448.                 case DEPTH_ID:
  1449.                 {
  1450.                     update_depth(go);
  1451.                 } break;
  1452.  
  1453.                 case SCRNPAL_ID:
  1454.                 {
  1455.                     update_color(go);
  1456.                 } break;
  1457.  
  1458.                 case CURPEN_ID:
  1459.                 {
  1460.                     update_pen(go);
  1461.                 } break;
  1462.  
  1463.                 case PALRED_ID:
  1464.                 {
  1465.                     struct Screen *scrn;
  1466.  
  1467.                     if(gl->cur_color) {
  1468.                         gl->cur_color->Red = code;
  1469.                         
  1470.                         // DON'T LAUGH!!  My 3000 is fast enough, and who
  1471.                         // cares about anyone else? :)
  1472.                         if( (gl->flags&NSF_MODIFY)
  1473.                             && (scrn=LockPubScreen(CURPUBNAME)) ) {
  1474.                             
  1475.                             SetRGB4(&scrn->ViewPort,
  1476.                                 gl->cur_color->ColorIndex,
  1477.                                 gl->cur_color->Red&0xF,
  1478.                                 gl->cur_color->Green&0xF,
  1479.                                 gl->cur_color->Blue&0xF);
  1480.                             UnlockPubScreen(NULL,scrn);
  1481.                         }
  1482.                     }
  1483.                 } break;
  1484.  
  1485.                 case PALGREEN_ID:
  1486.                 {
  1487.                     struct Screen *scrn;
  1488.  
  1489.                     if(gl->cur_color) {
  1490.                         gl->cur_color->Green = code;
  1491.                         if( (gl->flags&NSF_MODIFY)
  1492.                             && (scrn=LockPubScreen(CURPUBNAME)) ) {
  1493.                             
  1494.                             SetRGB4(&scrn->ViewPort,
  1495.                                 gl->cur_color->ColorIndex,
  1496.                                 gl->cur_color->Red&0xF,
  1497.                                 gl->cur_color->Green&0xF,
  1498.                                 gl->cur_color->Blue&0xF);
  1499.                             UnlockPubScreen(NULL,scrn);
  1500.                         }
  1501.                     }
  1502.                 } break;
  1503.  
  1504.                 case PALBLUE_ID:
  1505.                 {
  1506.                     struct Screen *scrn;
  1507.  
  1508.                     if(gl->cur_color) {
  1509.                         gl->cur_color->Blue = code;
  1510.                         if( (gl->flags&NSF_MODIFY)
  1511.                             && (scrn=LockPubScreen(CURPUBNAME)) ) {
  1512.                             
  1513.                             SetRGB4(&scrn->ViewPort,
  1514.                                 gl->cur_color->ColorIndex,
  1515.                                 gl->cur_color->Red&0xF,
  1516.                                 gl->cur_color->Green&0xF,
  1517.                                 gl->cur_color->Blue&0xF);
  1518.                             UnlockPubScreen(NULL,scrn);
  1519.                         }
  1520.                     }
  1521.                 } break;
  1522.  
  1523.                 case PENPAL_ID:
  1524.                 {
  1525.                     if(gl->cur_pen) {
  1526.                         *gl->cur_pen = code;
  1527.                     }
  1528.                 } break;
  1529.  
  1530.                 case OPEN_ID:
  1531.                 {
  1532.                     struct Screen *scrn;
  1533.                     
  1534.                     if(scrn=open_screen(go)) {
  1535.                         UnlockGadOutline(go);   // Window must be unlocked.
  1536.                         GO_CloseScreen(go);
  1537.                         set_modify(go,scrn);
  1538.                         if( !open_window(go,WA_PubScreen,scrn,TAG_END) ) {
  1539.                             UnlockPubScreen(NULL,scrn);
  1540.                             return HNDRES_CLOSEWIN;
  1541.                         }
  1542.                         get_colors(go,scrn);
  1543.                         UnlockPubScreen(NULL,scrn);
  1544.                     }
  1545.                 } break;
  1546.  
  1547.                 case MODIFY_ID:
  1548.                 {
  1549.                     struct Screen *scrn;
  1550.                     
  1551.                     // First, find the screen we are going to modify.
  1552.                     scrn = LockPubScreen(CURPUBNAME);
  1553.  
  1554.                     // Close our window and detach from screen.
  1555.                     UnlockGadOutline(go);   // Window must be unlocked.
  1556.                     GO_CloseScreen(go);
  1557.  
  1558.                     // Quick!  Before anyone sees us!
  1559.                     Forbid();
  1560.                     if(scrn) {
  1561.                         // Unlock the screen...
  1562.                         UnlockPubScreen(NULL,scrn);
  1563.  
  1564.                         // ... And close it!
  1565.                         if( CloseScrnTrack(scrn) ) {
  1566.                             scrn = NULL;            // It's all gone.
  1567.                         } else {
  1568.                             // Couldn't be closed... Lock it again.
  1569.                             scrn = LockPubScreen(CURPUBNAME);
  1570.                         }
  1571.                     }
  1572.                     Permit();
  1573.  
  1574.                     // If it no longer exists, try to re-open.
  1575.                     if(!scrn) scrn = open_screen(go);
  1576.                     
  1577.                     if( scrn ) {
  1578.                         set_modify(go,scrn);
  1579.                         if( !open_window(go,WA_PubScreen,scrn,TAG_END) ) {
  1580.                             UnlockPubScreen(NULL,scrn);
  1581.                             return HNDRES_CLOSEWIN;
  1582.                         }
  1583.                         get_colors(go,scrn);
  1584.                         UnlockPubScreen(NULL,scrn);
  1585.                     } else {
  1586.                         set_modify(go,NULL);
  1587.                         if( !open_window(go,WA_PubScreen,NULL,TAG_END) ) {
  1588.                             return HNDRES_CLOSEWIN;
  1589.                         }
  1590.                     }
  1591.  
  1592.                 } break;
  1593.  
  1594.             }
  1595.         }
  1596.     }
  1597.     
  1598.     return HNDRES_NORMAL;
  1599. }
  1600.  
  1601. void DestroyNewScrn(struct GadOutline *go)
  1602. {
  1603.     struct newscrn_globals *gl;
  1604.  
  1605.     if(!go) return;
  1606.     gl = go->go_UserData;
  1607.     
  1608.     UnlockGadOutline(go);   // Window must be unlocked.
  1609.     FreeGadOutline(go);
  1610.         
  1611.     if(gl) {
  1612.         if(gl->font_req) FreeAslRequest(gl->font_req);
  1613.         FreeVec(gl);
  1614.     }
  1615. }
  1616.  
  1617. struct GadOutline *CreateNewScrn(struct GadOutline *par_go,
  1618.                                  UBYTE *name,struct Screen *scrn,BOOL modify)
  1619. {
  1620.     struct GadOutline *go;
  1621.     struct newscrn_globals *gl;
  1622.     
  1623.     if(!par_go || !par_go->go_Window) return NULL;
  1624.     
  1625.     go = AllocGadOutline(&newscrn_outline[0],
  1626.             GOA_OutlineSize,    sizeof(newscrn_outline),
  1627.             GOA_UserIDCMP,      par_go->go_MsgPort,
  1628.             TAG_END);
  1629.     if(!go) return NULL;
  1630.     
  1631.     gl = AllocVec(sizeof(struct newscrn_globals),MEMF_PUBLIC|MEMF_CLEAR);
  1632.     if(!gl) {
  1633.         DestroyNewScrn(go);
  1634.         return NULL;
  1635.     }
  1636.     
  1637.     go->go_UserData = gl;
  1638.  
  1639.     if( (gl->font_req = (struct FontRequester *)
  1640.         AllocAslRequestTags(ASL_FontRequest,
  1641.             ASL_MinHeight,3,
  1642.             ASL_MaxHeight,999,
  1643.             TAG_END)) == NULL) {
  1644.         DestroyNewScrn(go);
  1645.         return NULL;
  1646.     }
  1647.  
  1648.     SetupBackFillHook(&gl->bf_hook,go);
  1649.     GO_SetObjAttrs(go,WINTAGS_ID,0,WA_BackFill,&gl->bf_hook,TAG_END);
  1650.  
  1651.     if(modify) gl->flags |= NSF_MODIFY;
  1652.  
  1653.     update_from_screen(go,name,scrn);
  1654.  
  1655.     if(gl->flags & NSF_MODIFY) {
  1656.     
  1657.         set_modify(go,scrn);
  1658.         if( !open_window(go,WA_PubScreen,scrn,TAG_END) ) {
  1659.             DestroyNewScrn(go);
  1660.             return NULL;
  1661.         }
  1662.  
  1663.     } else {
  1664.     
  1665.         set_modify(go,NULL);
  1666.         if( !open_window(go,WA_CustomScreen,par_go->go_Screen,TAG_END) ) {
  1667.             DestroyNewScrn(go);
  1668.             return NULL;
  1669.         }
  1670.     }
  1671.  
  1672.     return go;
  1673. }
  1674.